#include "Leave.h"
#include <assert.h>
#include "SymtableV0.h"

const int DEBUG_PRINT_TYPE_CHANGES = 0;

ScannerV0* Leave::scanner;

Leave::Leave(Token* token) : token(token)
{
    type = TYPE_NO;
}

Leave::~Leave()
{
}

void Leave::setScanner(ScannerV0* scanner){
    Leave::scanner = scanner;
}

Token* Leave::getToken()
{
    return token;
}

TType Leave::getType()
{
    SymtabEntry* entry = Leave::scanner->getSymtabEntry(token->getKey());
    Information* info = &entry->getInfo();
    if(DEBUG_PRINT_TYPE_CHANGES) printf("getType() of %p: %d\n", this, info->type);
    type = info->type;
  
    return type;
}

void Leave::setType(TType type)
{
    SymtabEntry* entry = Leave::scanner->getSymtabEntry(token->getKey());
    Information* info = &entry->getInfo();
    if(DEBUG_PRINT_TYPE_CHANGES) printf("setType() of %p: %d\n", this, type);
    info->type = type;
    this->type = type;
}

//void Leave::create(void (*typeCheckFunc) (ParseTree* tree)){} // do nothing
//void create(void (*typeCheckFunc) (ParseTree*), void (*makeCodeFunc) (ParseTree*));
void Leave::typeCheck(){} // do nothing
void Leave::makeCode(){} // do nothing

char* Leave::getLexem()
{
    return scanner->lookup(token->getKey()).lexem;
}

int Leave::getValue()
{
    return token->getInt();
}
